package lodsve.test.mongodb.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lodsve.test.mongodb.domain.Demo;
import lodsve.test.mongodb.domain.Test;
import lodsve.test.mongodb.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * .
 *
 * @author sunhao(sunhao.java @ gmail.com)
 * @version 1.0 2017/12/7 16:24
 */
@Api(value = "MongoDB测试", description = "MongoDB测试")
@RestController
@RequestMapping("/demo")
public class DemoController {
    @Autowired
    private DemoService demoService;

    @ApiOperation(value = "保存到test", notes = "保存到test")
    @ApiResponses({@ApiResponse(code = 200, message = "保存成功")})
    @RequestMapping(value = "/saveTest", method = RequestMethod.POST)
    public void save1(@ApiParam(name = "demo", value = "需要保存的") @RequestBody Test demo) {
        demoService.save1(demo);
    }

    @ApiOperation(value = "从test获取", notes = "从test获取")
    @ApiResponses({@ApiResponse(code = 200, message = "获取成功")})
    @RequestMapping(value = "/test/{id}", method = RequestMethod.GET)
    public Test get1(@ApiParam(name = "id", value = "ID") @PathVariable("id") Long id) {
        return demoService.get1(id);
    }

    @ApiOperation(value = "获取test全部", notes = "获取test全部")
    @ApiResponses({@ApiResponse(code = 200, message = "获取全部成功")})
    @RequestMapping(value = "/listTest", method = RequestMethod.GET)
    public List<Test> list1() {
        return demoService.list1();
    }

    @ApiOperation(value = "保存到demo", notes = "保存到demo")
    @ApiResponses({@ApiResponse(code = 200, message = "保存成功")})
    @RequestMapping(value = "/saveDemo", method = RequestMethod.POST)
    public void save2(@ApiParam(name = "demo", value = "需要保存的") @RequestBody Demo demo) {
        demoService.save2(demo);
    }

    @ApiOperation(value = "从demo获取", notes = "从demo获取")
    @ApiResponses({@ApiResponse(code = 200, message = "获取成功")})
    @RequestMapping(value = "/demo/{id}", method = RequestMethod.GET)
    public Demo get2(@ApiParam(name = "id", value = "ID") @PathVariable("id") Long id) {
        return demoService.get2(id);
    }

    @ApiOperation(value = "获取demo全部", notes = "获取demo全部")
    @ApiResponses({@ApiResponse(code = 200, message = "获取全部成功")})
    @RequestMapping(value = "/listDemo", method = RequestMethod.GET)
    public List<Demo> list2() {
        return demoService.list2();
    }
}
